-- Options are automatically loaded before lazy.nvim startup
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
-- Add any additional options here

-- Tab Width: 4
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4

-- Disable Amimation
vim.g.snacks_animate = false

-- Shell
if os.execute("nu --version") == 0 then
  -- nu
  vim.opt.shell = "nu"
  vim.opt.shellcmdflag = "-c"
elseif vim.fn.has("win32") == 1 and os.execute("pwsh --version") == 0 then
  -- pwsh (Powershell 7)
  vim.opt.shell = "pwsh.exe -NoLogo"
  vim.opt.shellcmdflag =
    "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;"
end

-- Neovide
if vim.g.neovide then
  -- local windows_font = "FiraCode Nerd Font:h14"
  local windows_font = "ComicShannsMono Nerd Font Mono,微软雅黑:h14"
  -- local linux_font = "FiraCode Nerd Font:h12"
  local linux_font = "ComicShannsMono Nerd Font Mono,文泉驿正黑:h14"

  if vim.fn.has("win32") == 1 then
    vim.o.guifont = windows_font
  else
    vim.o.guifont = linux_font
  end

  vim.g.neovide_refresh_rate = 60
  vim.g.neovide_refresh_rate_idle = 1

  vim.g.neovide_opacity = 0.9

  vim.g.neovide_hide_mouse_when_typing = true
  vim.g.neovide_confirm_quit = true

  -- vim.g.neovide_cursor_vfx_mode = "railgun"
  vim.g.neovide_cursor_vfx_mode = "sonicboom"
  vim.g.neovide_cursor_trail_size = 0.5
  vim.g.neovide_cursor_antialiasing = true

  vim.g.neovide_cursor_animation_length = 0.05

  vim.g.neovide_scroll_animation_length = 0.1
  vim.g.neovide_scroll_animation_far_lines = 1

  vim.g.experimental_layer_grouping = true -- If has problems when seeing floating window, set it to false.
  vim.g.neovide_floating_blur_amount_x = 2.0
  vim.g.neovide_floating_blur_amount_y = 2.0

  vim.g.neovide_floating_shadow = true
  vim.g.neovide_floating_z_height = 10
  vim.g.neovide_light_angle_degrees = 45
  vim.g.neovide_light_radius = 5

  vim.g.neovide_confirm_quit = true
  vim.g.neovide_detach_on_quit = "always_quit"

  -- Disable IME when in normal mode.
  local function set_ime(args)
    if args.event:match("Enter$") then
      vim.g.neovide_input_ime = true
    else
      vim.g.neovide_input_ime = false
    end
  end

  local ime_input = vim.api.nvim_create_augroup("ime_input", { clear = true })

  vim.api.nvim_create_autocmd({ "InsertEnter", "InsertLeave" }, {
    group = ime_input,
    pattern = "*",
    callback = set_ime,
  })

  vim.api.nvim_create_autocmd({ "CmdlineEnter", "CmdlineLeave" }, {
    group = ime_input,
    pattern = "[/\\?]",
    callback = set_ime,
  })
end

-- Load specific
pcall(require, "config.specific")
